using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;
using SharpCore.Utilities;

namespace Dating.DA
{
	public class WhomViewedDA
	{
		#region Fields

		protected string connectionStringName;

		#endregion

		#region Constructors
		public WhomViewedDA()
		{
		}

		public WhomViewedDA(string connectionStringName)
		{
			ValidationUtility.ValidateArgument("connectionStringName", connectionStringName);

			this.connectionStringName = connectionStringName;
		}

		#endregion

		#region Methods

		/// <summary>
		/// Saves a record to the WhomViewed table.
		/// </summary>
		public  int Insert(WhomViewed whomViewed)
		{
			ValidationUtility.ValidateArgument("whomViewed", whomViewed);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", whomViewed.TenantID),
				new SqlParameter("@ProfileID", whomViewed.ProfileID),
				new SqlParameter("@WhomIViewedID", whomViewed.WhomIViewedID),
				new SqlParameter("@IsDeleted", whomViewed.IsDeleted),
				new SqlParameter("@UpdateDate", whomViewed.UpdateDate),
				new SqlParameter("@UpdatedBy", whomViewed.UpdatedBy)
			};

			whomViewed.ViewID = Convert.ToInt32(SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "WhomViewedInsert", parameters));
			return whomViewed.ViewID;
		}

		/// <summary>
		/// Updates a record in the WhomViewed table.
		/// </summary>
		public  int Update(WhomViewed whomViewed)
		{
			ValidationUtility.ValidateArgument("whomViewed", whomViewed);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ViewID", whomViewed.ViewID),
				new SqlParameter("@TenantID", whomViewed.TenantID),
				new SqlParameter("@ProfileID", whomViewed.ProfileID),
				new SqlParameter("@WhomIViewedID", whomViewed.WhomIViewedID),
				new SqlParameter("@IsDeleted", whomViewed.IsDeleted),
				new SqlParameter("@UpdateDate", whomViewed.UpdateDate),
				new SqlParameter("@UpdatedBy", whomViewed.UpdatedBy)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "WhomViewedUpdate", parameters));
		}

		/// <summary>
		/// Deletes a record from the WhomViewed table by its primary key.
		/// </summary>
		public  int Delete(int viewID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ViewID", viewID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "WhomViewedDelete", parameters));
		}

		/// <summary>
		/// Deletes a record from the WhomViewed table by a foreign key.
		/// </summary>
		public  int DeleteAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "WhomViewedDeleteAllByProfileID", parameters));
		}

		/// <summary>
		/// Deletes a record from the WhomViewed table by a foreign key.
		/// </summary>
		public  int DeleteAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "WhomViewedDeleteAllByTenantID", parameters));
		}

		/// <summary>
		/// Selects a single record from the WhomViewed table.
		/// </summary>
		public  WhomViewed Select(int viewID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ViewID", viewID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "WhomViewedSelect", parameters))
			{
				if (dataReader.Read())
				{
					return MakeWhomViewed(dataReader);
				}
				else
				{
					return null;
				}
			}
		}

		/// <summary>
		/// Selects all records from the WhomViewed table.
		/// </summary>
		public  List<WhomViewed> SelectAll(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)
			};
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "WhomViewedSelectAll", parameters))
			{
				List<WhomViewed> whomViewedList = new List<WhomViewed>();
				while (dataReader.Read())
				{
					WhomViewed whomViewed = MakeWhomViewed(dataReader);
					whomViewedList.Add(whomViewed);
				}

				return whomViewedList;
			}
		}

		/// <summary>
		/// Selects all records from the WhomViewed table by a foreign key.
		/// </summary>
		public  List<WhomViewed> SelectAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "WhomViewedSelectAllByProfileID", parameters))
			{
				List<WhomViewed> whomViewedList = new List<WhomViewed>();
				while (dataReader.Read())
				{
					WhomViewed whomViewed = MakeWhomViewed(dataReader);
					whomViewedList.Add(whomViewed);
				}

				return whomViewedList;
			}
		}

		/// <summary>
		/// Selects all records from the WhomViewed table by a foreign key.
		/// </summary>
		public  List<WhomViewed> SelectAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "WhomViewedSelectAllByTenantID", parameters))
			{
				List<WhomViewed> whomViewedList = new List<WhomViewed>();
				while (dataReader.Read())
				{
					WhomViewed whomViewed = MakeWhomViewed(dataReader);
					whomViewedList.Add(whomViewed);
				}

				return whomViewedList;
			}
		}

		/// <summary>
		/// Creates a new instance of the WhomViewed class and populates it with data from the specified SqlDataReader.
		/// </summary>
		protected  WhomViewed MakeWhomViewed(SqlDataReader dataReader)
		{
			WhomViewed whomViewed = new WhomViewed();
			whomViewed.ViewID = SqlClientUtility.GetInt32(dataReader, "ViewID", 0);
			whomViewed.TenantID = SqlClientUtility.GetInt32(dataReader, "TenantID", 0);
			whomViewed.ProfileID = SqlClientUtility.GetInt32(dataReader, "ProfileID", 0);
			whomViewed.WhomIViewedID = SqlClientUtility.GetInt32(dataReader, "WhomIViewedID", 0);
			whomViewed.IsDeleted = SqlClientUtility.GetBoolean(dataReader, "IsDeleted", false);
			whomViewed.UpdateDate = SqlClientUtility.GetDateTime(dataReader, "UpdateDate", DateTime.Now);
			whomViewed.UpdatedBy = SqlClientUtility.GetString(dataReader, "UpdatedBy", String.Empty);

			return whomViewed;
		}

		#endregion
	}
}
